<template>
    <i class="el-icon-fa-clock-o">&nbsp; {{times}}</i>
</template>

<script>
    export default {
        data (){
            return {
                times: ''
            }
        },
        created(){
            setInterval(() => {
                this.times = showTime();
            }, 1000);
        }
    }

    function showTime() {
        let date = new Date();
        let year = date.getFullYear();//当前年份
        let month = date.getMonth();//当前月份
        let data = date.getDate();//天
        let hours = date.getHours();//小时
        let minute = date.getMinutes();//分
        let second = date.getSeconds();//秒
        return year + "-" + formatter((month + 1)) + "-" + formatter(data) + " " + formatter(hours) + ":" + formatter(minute) + ":" + formatter(second);
    }

    function formatter(num) {
        return num >= 10 ? num : "0" + num;
    }
</script>

<style scoped>
    i {
        font-family: 微软雅黑;
        font-size: 13px;
        line-height: 28px;
        margin: 0 auto;
        padding-left: 10px;
    }
</style>